function [max_action, Q] = FindBestAction(P,S,mode,range, policy)

global num_players_r;
global num_players_b;

if(P{2}=='r')
    num_players = num_players_r;
    num_opponents = num_players_b;
else
    num_players = num_players_b;
    num_opponents = num_players_r;
end

P_num = P{3};

max_action = range(1); % default action
F = GetFeatures(P,S,mode,max_action);
Q = Qvalue(F, policy(P_num,:));

for i = 2:numel(range)
    
    action = range(i);
    F_current = GetFeatures(P,S,mode,action);
    Q_current = Qvalue(F_current, policy(P_num,:));
    
    if Q_current > Q
        max_action = action;
        Q = Q_current;
    end
end

%fprintf(log_id,'Player %d | %s | \n', P_num, ActionToString(max_action, num_players, num_opponents));

end